package nancal.mp.mvc.dev

import nbcp.base.annotation.mvc.OpenAction
import nbcp.base.comm.ApiResult
import nbcp.base.comm.JsonMap
import nbcp.base.extend.FromListYarmText
import nbcp.base.extend.Skip
import nbcp.base.extend.ToYaml
import nbcp.base.extend.deepJoin
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@OpenAction
@RestController
@RequestMapping("/dev/tools")
class ToolsController {
    @PostMapping("/yaml-join")
    fun yamlJoin(@RequestBody content: String): ApiResult<String> {
        var list = content.FromListYarmText(JsonMap::class.java)

        var first = list.first() as Map<String, Any?>;
        list.Skip(1).forEach {
            first = first.deepJoin(it)
        }

        var result = first.ToYaml();
        return ApiResult.of(result)
    }
}